/**观察者类 */
export class Notifier {
    private observers:Observer[] = [];
    constructor(){

    }
    add(obs:Observer){
        this.observers.push(obs)
    }

    remove(obs:Observer){
        this.observers = this.observers.filter(item=>obs!==item);
    }
    notify(){
        let len = this.observers.length;
        for (let index = 0; index < len; index++) {
            this.observers[index].update();
        }
    }

}

export class Observer {
    private fun:Function;
    constructor(fun:Function){
        this.fun = fun;
    }
    update() {
        this.fun()
    }
}